//
//  TaskListModel.m
//  Trackit
//
//  Created by yaodaobin on 2017/4/3.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import "TaskListModel.h"

@implementation TaskListModel

- (instancetype)initWithData:(NSDictionary *)data {
    self = [super init];
    if (self) {
        self.collectDataType = [data[@"CollectDataType"] integerValue];
        self.collectDataTypeName = [CommonFunction getValueFromDic:data withKey:@"CollectDataTypeName"];
        self.createDate = [data[@"CreateDate"] longLongValue] / 1000;
        self.createUser = [CommonFunction getValueFromDic:data withKey:@"CreateUser"];
        self.createUserName = [CommonFunction getValueFromDic:data withKey:@"CreateUserName"];
        self.taskDescription = [CommonFunction getValueFromDic:data withKey:@"Description"];
        self.finished = [data[@"Finished"] boolValue];
        self.latestSubmitDate = [CommonFunction getValueFromDic:data withKey:@"LatestSubmitDate"];
        self.startDate = [CommonFunction getValueFromDic:data withKey:@"StartDate"];
        self.subitTimes = [NSString stringWithFormat:@"%ld",(long)[data[@"SubmitTimes"] integerValue]];
        self.taskDetailID = [CommonFunction getValueFromDic:data withKey:@"TaskDetailID"];
        self.taskID = [NSString stringWithFormat:@"%ld",(long)[data[@"TaskID"] integerValue]];
        self.taskName = [CommonFunction getValueFromDic:data withKey:@"TaskName"];
        self.taskStatusName = [CommonFunction getValueFromDic:data withKey:@"TaskStatusName"];
        self.taskStatusType = [data[@"TaskStatusType"] integerValue];
        self.userID = [NSString stringWithFormat:@"%ld",(long)[data[@"UserID"] integerValue]];
        
        
        NSDate *detaildate = [NSDate dateWithTimeIntervalSince1970:self.createDate];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
        NSString *currentDateStr = [dateFormatter stringFromDate:detaildate];
        self.createCalendarDate = currentDateStr;
        
        self.isLine = self.collectDataType == CollectDataTypeLine;
        self.locationInfo = [[TSLocation alloc] init];
    }
    return self;
}

- (BOOL)localPathExisted {
    return [APP_DELEGATE localPathExisted:self.searchCacheIDString];
}

- (NSString *)searchCacheIDString {
    return [NSString stringWithFormat:@"%@Task[%@]User[%@]",self.taskName,self.taskDetailID,APP_DELEGATE.user.userID];
}

- (NSString *)cacheString {
    return [NSString stringWithFormat:@"Task_%@_User_%@_",self.taskDetailID,APP_DELEGATE.user.userID];
}


+ (NSMutableArray *)getPropertyHeaderKeyArray:(CollectDataType)type {
    NSMutableArray *tempArray = [NSMutableArray array];;
    switch (type) {
        case CollectDataTypeLine:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"录入日期",nil),@0,@YES,@(PropertyTypePicker)],
                                  @[NSLocalizedString(@"编号",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"名称",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"拥有者",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"备注(可选)",nil),@0,@NO,@(PropertyTypeDefault)],
                                  nil]];
        }
            break;
        default:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"录入日期",nil),@0,@YES,@(PropertyTypePicker)],
                                  @[NSLocalizedString(@"牧户名",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"性别",nil),@0,@NO,@(PropertyTypeOther)],
                                  @[NSLocalizedString(@"身份证号",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"确权证号",nil),@0,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"州县乡",nil),@0,@YES,@(PropertyTypePicker)],
                                  @[NSLocalizedString(@"村或合作社",nil),@0,@YES,@(PropertyTypePicker)],
                                  nil]];

        }
            break;
    }
    return tempArray;

}

+ (NSMutableArray *)getPropertyKeyArray:(CollectDataType)type {
    NSMutableArray *tempArray = [self getPropertyHeaderKeyArray:type];
    switch (type) {
        case CollectDataTypePointAnimal:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"牛成年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"牛幼年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  nil]];
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"羊成年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"羊幼年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  nil]];
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"马成年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"马幼年数量",nil),@1,@NO,@(PropertyTypeDefault)],
                                  nil]];

        }
            break;
        case CollectDataTypeLine:
        {
        }
            break;
        case CollectDataTypePointGrass:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @[NSLocalizedString(@"草高(厘米)",nil),@2,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"草覆盖度(%)",nil),@2,@NO,@(PropertyTypeDefault)],
                                  @[NSLocalizedString(@"草种类",nil),@0,@NO,@(PropertyTypeDefault)],
                                  nil]];
        }
            break;
    }
    return tempArray;
}

+ (NSMutableArray *)getPropertyHeaderValueArray:(CollectDataType)type {
    NSMutableArray *tempArray = [NSMutableArray array];;
    switch (type) {
        case CollectDataTypeLine:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @"StatisticalTime",
                                  @"ID",
                                  @"Name",
                                  @"Owner",
                                  @"Description",
                                  nil]];
        }
            break;
        default:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @"StatisticalTime",
                                  @"TheName",
                                  @"Sex",
                                  @"Identification",
                                  @"GrasslandCertificateNo",
                                  @"City",
//                                  @"County",
//                                  @"Township",
                                  @"Village",
                                  nil]];
        }
            break;
    }
    return tempArray;
    
}

+ (NSMutableArray *)getPropertyValueArray:(CollectDataType)type {
    NSMutableArray *tempArray = [self getPropertyHeaderValueArray:type];
    switch (type) {
        case CollectDataTypePointAnimal:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @"Cattle",
                                  @"CattleYou",
                                  nil]];
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @"Sheep",
                                  @"SheepYou",
                                  nil]];
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                                  @"Horse",
                                  @"HorseYou",
                                  nil]];

        }
            break;
        case CollectDataTypeLine:
        {
        }
            break;
        case CollectDataTypePointGrass:
        {
            [tempArray addObject:[NSMutableArray arrayWithObjects:
                              @"GrassHeight",
                              @"Grassfc",
                              @"GrassSpecies",
                                  nil]];
            
        }
            break;
    }
    return tempArray;
}
@end
